package com.xuanyuan.base.utils

import android.app.Activity
import android.os.Bundle
import android.content.Intent
import kotlin.jvm.JvmOverloads
import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.android.arouter.facade.enums.RouteType

/**
 * Copyright (C), 2017-2022, Anker
 * FileName: ArouterUtils  Arouter路由工具类
 *
 * @author ken.luo
 * Date: 2022/6/3 18:20
 * Description: Activity 跳转工具
 * History:
 * 创建者 : ken.luo
 * <author>     <time>     <version>      <desc>
 * 作者姓名      修改时间      版本号          描述
</desc></version></time></author> */
object ArouterUtils {

    fun startActivityCommon(activity: Activity, bundle: Bundle?, cls: Class<out Activity?>) {
        val intent = Intent(activity, cls)
        if (bundle != null) {
            intent.putExtras(bundle)
        }
        activity.startActivity(intent)
    }

    fun startActivityCommon(activity: Activity, cls: Class<out Activity?>) {
        val intent = Intent(activity, cls)
        activity.startActivity(intent)
    }

    fun startActivityForResult(activity: Activity, requestCode: Int, cls: Class<out Activity?>) {
        val intent = Intent(activity, cls)
        activity.startActivityForResult(intent, requestCode)
    }


    fun startActivityArouter(path: String, bundle: Bundle? = null) {
        startActivityArouter(null, path, bundle, -1)
    }

    @JvmOverloads
    fun startActivityArouter(activity: Activity, path: String, requestCode: Int = -1) {
        startActivityArouter(activity, path, null, requestCode)
    }

    fun startActivityArouter(activity: Activity?, path: String, bundle: Bundle?, requestCode: Int) {
        val postcard = ARouter.getInstance()
            .build(path)
            .with(bundle)
        if (activity != null) {
            postcard.type = RouteType.ACTIVITY
        }
        postcard.navigation(activity, requestCode)
    }

}